package com.thread.base;

/**
 * @User xiangyl
 * @Data 2020/10/3
 */
public class ThreadInterrupt extends Thread{

    private volatile boolean isStop=false;

    public static void main(String[] args) throws InterruptedException {
        ThreadInterrupt threadInterrupt = new ThreadInterrupt();
        threadInterrupt.start();
        System.out.println("start interrupt threadInterrupt");
        Thread.sleep(1*1000);
        threadInterrupt.interrupt();
        Thread.sleep(1*1000);
        threadInterrupt.isStop=true;
    }


    public void run() {
        while (!isStop){
            System.out.println(this.isInterrupted());
        }
        try {
            Thread.sleep(1*1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
            System.out.println("current status is "+this.isInterrupted());
        }
    }
}
